/**
 * 
 */
package com.mc.sql;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

import org.apache.commons.io.FileUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import cn.hutool.core.date.DateUtil;

/**
 * @author w.weizhen
 *
 */
public class GenerateSQL {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		insert();//生成插入数据sql
		
		//System.out.println(String.format("%.2f", Math.random()));
		
	}
	
	
//	public static void insert()
//	{
//		try {
//			String insert  = "INSERT INTO t_devicedata_200001 (mainDeviceId,deviceId,deviceValue,deviceValueFmt,collectionTime) VALUES ";
//			String mainDeviceId="WG285LL0718092500239";
//			String deviceId="ca0608c3d5d6469490ce0b3550938878";
//			List<String> lines=new ArrayList<String>();
//			lines.add(insert);
//			for (int i = 0; i < 24; i++) {
//				for (int j = 0; j < 60; j++) {
//					if(j/5!=0) {continue;}
//					String time="2000-01-01 "+String.format("%02d",i)+":"+String.format("%02d",j)+":00";
//					double val=Math.floor(Math.random() * Math.floor(14));
//					String sql = "('"+mainDeviceId+"','"+deviceId+"',"+val+","+val+",'"+time+"'),";
//					lines.add(sql);
//				}
//			}
//			
////			for (int i = 0; i < 1000; i++) {
////				String h = String.format("%02d", (int)Math.floor(Math.random() * Math.floor(12)));
////				String m = String.format("%02d", (int)Math.floor(Math.random() * Math.floor(60)));
////				String s = String.format("%02d", (int)Math.floor(Math.random() * Math.floor(60)));
////				String time="2000-01-01 "+h+":"+m+":"+s;
////				double val=Math.floor(Math.random() * Math.floor(14));
////				//String val = String.format("%.2f", Math.random());
////				String sql = "('"+mainDeviceId+"','"+deviceId+"',"+val+","+val+",'"+time+"','"+time+"'),";
////				//sb.append(sql);
////				
////				lines.add(sql);
////			}
//			//生成本地文件
//	        //FileUtils.writeStringToFile(new File("G:/workspace/file/insert.txt"), sb.toString(), "UTF-8");
//	        FileUtils.writeLines(new File("D:/hynetic/0.txt"),lines,true);
//	        
////			String insert  = "INSERT INTO t_proj_area_devicedata_2021 (areaId,areaName,areaCode,areaOrgId,assetId,assetName,assetSno,datas,collectionTime,createTime) VALUES ";
////	        
////	        String areaId = "9007c79000be41adbc4dd8a6e3956dc4";
////	        String areaName = "北京瑞力泰莱科技开发有限公司";
////	        String areaCode = "QVZO598681444192028";
////	        String areaOrgId = "fb513ffcb15e4717825fd316215dbacb";
////	        String assetId = "94ee3f0bee284b68b044ac75dfe3d13c";
////	        String assetName = "北京瑞力泰莱科技开发有限公司";
////	        String assetSno = "LENX598838628556640";
////	        
////	        List<String> lines=new ArrayList<String>();
////	        for (int i = 0; i < 1000; i++) 
////	        {
////	        	JSONObject d_codJSON = new JSONObject();d_codJSON.put("nm", "cod");d_codJSON.put("v", Math.random());d_codJSON.put("un", "");
////	        	JSONObject d_ozoneJSON = new JSONObject();d_ozoneJSON.put("nm", "臭氧");d_ozoneJSON.put("v", Math.random());d_ozoneJSON.put("un", "mg/ml");
////	        	JSONObject d_ocJSON = new JSONObject();d_ocJSON.put("nm", "耗氧量");d_ocJSON.put("v", Math.random());d_ocJSON.put("un", "");
////	        	JSONObject d_doJSON = new JSONObject();d_doJSON.put("nm", "溶解氧");d_doJSON.put("v", Math.random());d_doJSON.put("un", "");
////	        	JSONObject d_rtradiationJSON = new JSONObject();d_rtradiationJSON.put("nm", "实时辐射量");d_rtradiationJSON.put("v", Math.random());d_rtradiationJSON.put("un", "");
////	        	JSONObject d_nclhJSON = new JSONObject();d_nclhJSON.put("nm", "一氯胺(总氯)");d_nclhJSON.put("v", Math.random());d_nclhJSON.put("un", "");
////	        	
////	        	JSONObject datasJSON = new JSONObject();
////	        	datasJSON.put("d_cod", d_codJSON);
////	        	datasJSON.put("d_ozone", d_ozoneJSON);
////	        	datasJSON.put("d_oc", d_ocJSON);
////	        	datasJSON.put("d_do", d_doJSON);
////	        	datasJSON.put("d_rtradiation", d_rtradiationJSON);
////	        	datasJSON.put("d_nclh", d_nclhJSON);
////	        	String datas = datasJSON.toJSONString();
////	        	
////	        	String d = String.format("%02d", (int)Math.floor(Math.random() * Math.floor(31)));
////	        	String h = String.format("%02d", (int)Math.floor(Math.random() * Math.floor(12)));
////				String m = String.format("%02d", (int)Math.floor(Math.random() * Math.floor(60)));
////				String s = String.format("%02d", (int)Math.floor(Math.random() * Math.floor(60)));
////				String time="2021-04-"+d+" "+h+":"+m+":"+s;
////				String collectionTime = time;
////		        String createTime = time;
////		        String  values = "('"+areaId+"','"+areaName+"','"+areaCode+"','"+areaOrgId+"','"+assetId+"','"+assetName+"','"+assetSno+"','"+datas+"','"+collectionTime+"','"+createTime+"');";
////				lines.add(insert+values);
////			}
////	        FileUtils.writeLines(new File("G:/workspace/file/QVZO598681444192028-LENX598838628556640-2021-04.txt"),lines,true);
//	        
//	        
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//	}
	
	
	private static final String write_path = "D:/文件/日期文件/202208170/";
	private static List<String> ids = Arrays.asList("6d2028ff888644439624a4500029320c", "14eb4419cd854eb5a35a152d1345a29e", "d56e075221ff4cf5bdcd95572a1e1a1e", "ca368f06f1594659aa32ea4d841f2426", "00a8025f04de4e8bb894e12f944d5ee6", "d6033c9b984e43128cd79e228e6d363f");
	private static String orgId = "fb513ffcb15e4717825fd316215dbacb";
	private static String orgName = "上海市静安区卫生监督委员会";
	private static String personId = "c077d09a39454678a55deeda21734bf2";
	private static String personName = "王万林";
	private static String personPhone = "13727736080";
	private static String personCardId = "110101192010108477";
	private static String createTime = DateUtil.now();
	private static String createAccountId = "fe474458b2ad4dffac9a8fc79f7fb4e2";
	private static String disabled = "0";
	private static void insert()
	{
		String insert  = "INSERT INTO `sws_sell_water_check` (`assetId`, `checkTime`, `result`, `orgId`, `orgName`, `personId`, `personName`, `personPhone`, `personCardId`, `createTime`, `createAccountId`, `disabled`) VALUES ";
		List<String> lines=new ArrayList<String>();
		for (int i = 0; i < 24; i++) {
			for (int j = 0; j < 60; j++) {
				if(j/5!=0) {continue;}
				String time="2022-08-02 "+String.format("%02d",i)+":"+String.format("%02d",j);
				double val=Math.floor(Math.random() * Math.floor(10));
				JSONObject result = new JSONObject();
				result.put("001", JSON.parseObject("{\"common\": \""+String.format("%.0f",Math.random() * Math.floor(10))+"\"}"));
				result.put("002", JSON.parseObject("{\"common\": \""+String.format("%.0f",Math.random() * Math.floor(10))+"\"}"));
				result.put("003", JSON.parseObject("{\"common\": \""+String.format("%.0f",Math.random() * Math.floor(100))+"\"}"));
				result.put("004", JSON.parseObject("{\"common\": \""+Arrays.asList("未检测","未检出","微弱","弱","强","0","1").get(new Random().nextInt(7))+"\"}"));
				result.put("005", JSON.parseObject("{\"common\": \""+String.format("%.0f",Math.random() * Math.floor(10))+"\"}"));
				String sql = "('"+ids.get(new Random().nextInt(ids.size()))+"','"+time+"','"+result.toJSONString()+"','"+orgId+"','"+orgName+"','"+personId+"','"+personName+"','"+personPhone+"','"+personCardId+"','"+createTime+"','"+createAccountId+"',"+disabled+");";
				lines.add(insert+sql);
			}
		}
		
		System.out.println(lines.toString());
		
		try {
			FileUtils.writeLines(new File(write_path+"/"+System.currentTimeMillis()+".sql"), lines, true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}